package logic

import (
	"context"
	"work-safety/models/mysql"

	"work-safety/workrpc/internal/svc"
	"work-safety/workrpc/workrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BaiAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBaiAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BaiAddLogic {
	return &BaiAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BaiAddLogic) BaiAdd(in *workrpc.BaiAddRequest) (*workrpc.BaiAddResponse, error) {
	// todo: add your logic here and delete this line
	bai := mysql.Bai{
		Title: in.Title,
		Image: in.Image,
		Text:  in.Text,
		Price: float64(in.Price),
	}
	mysql.DB.Debug().Create(&bai)

	return &workrpc.BaiAddResponse{
		BaiId: int64(bai.ID),
	}, nil
}
